// pages/mine/address/addAddress/addAddress.js
const app = getApp();
const util = require("../../../../utils/util.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    region: ['湖北省', '武汉市', '江夏区'],
    name: "",
    cellphone: "",
    address: ""
  },

  // 选择省市
  bindRegionChange: function (e) {
    // console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      region: e.detail.value
    })
  },

  // 获取收货人姓名
  shName: function(e) {
    let that = this
    that.setData({
      name: e.detail.value
    })
  },

  // 获取收货人电话
  shPhone: function (e) {
    let that = this
    that.setData({
      cellphone: e.detail.value
    })
  },

  // 获取收货人详细地址
  shDetailAdd: function (e) {
    let that = this
    that.setData({
      address: e.detail.value
    })
  },

  // 点击保存
  toNewSize :function(e) {
    let that = this
    // 发送添加地址信息
    let addAddUrl = app.globalData.baseUrl + "weixin/addAddress"
    let name = that.data.name
    let cellphone = that.data.cellphone
    let address = that.data.address
    let region = that.data.region
    if(name==""){
      wx.showModal({
        content: '请输入姓名',
        showCancel: false
      })
      return
    }
    if (cellphone == "") {
      wx.showModal({
        content: '请输入手机号',
        showCancel: false
      })
      return
    } if (region == "") {
      wx.showModal({
        content: '请输入详细地址',
        showCancel: false
      })
      return
    }
    let data = {
      cid: wx.getStorageSync('cid'),
      name: name,
      cellphone: cellphone,
      address: address,
      region: region
    }
    util.requestLoading(addAddUrl, data, "GET").then(res => {
      // console.log(res)
      wx.navigateBack({
        delta:1
      })
    })
  },
})